/**
 * Created by 周颖 on 2017/7/26.
 * 
 * axios post请求默认提交的是JSON,如果需要提交 application/x-www-form-urlencoded =>
 * 1、引入 import queryString from 'querystring';
 * 2、参数 queryString.stringify(para)
 * [参考](https://github.com/mzabriskie/axios#using-applicationx-www-form-urlencoded-format)
 * 
 * 
 * [接口地址](http://59.107.26.181:8086/swagger-ui.html)
 */

import axios from 'axios';
import queryString from 'querystring';


let api = {
    postCouponList: '/api-active/v1/api/coupon/backend/list', //卡券列表 
    getCouponLimitType: '/api-active/v1/api/OptionDetails/limit/type', //卡券限制领取方式 
    getCouponExpireType: '/api-active/v1/api/OptionDetails/expire/type', //卡券过期类型 
    postCouponNew: '/api-active/v1/api/coupon/backend/store', //创建卡券 
    postCodeIds: '/api-active/v1/api/coupon/exchangeCode/import', //导入卡券
    postHandleCouponStatus: '/api-active/v1/api/coupon/backend/status/change', //修改卡券状态

    getCouponDetail: '/api-active/v1/api/coupon/backend/detail/', //查询卡券详情
    getCouponExchangeCode: '/api-active/v1/api/coupon/exchangeCode/list', //兑换卡券详情-卡号

    postCheckUserValidate: '/api-active/v1/api/coupon/backend/sendCustomer/validate/v2', //发放卡券－查询用户手机号
    postSendCoupon: '/api-active/v1/api/coupon/backend/sendCustomer', //发放卡券－批量送券

    getCouponRecordList: '/api-active/v1/api/wallet/list', //卡券管理－查询列表
    getCouponRecordExportExcel: '/api-active/v1/api/wallet/excel', //卡券管理－导出列表
}


//查询卡券列表 http://59.107.26.181:8086/swagger-ui.html#!/coupon-back-end-api-controller/listUsingGET_3
const postCouponList = (parm) => {
    return axios.post(api.postCouponList, parm)
}


const getCouponLimitType = () => { return axios.get(api.getCouponLimitType) }

const getCouponDetail = (id) => { return axios.get(api.getCouponDetail + id) }

const getCouponExpireType = () => { return axios.get(api.getCouponExpireType) }

const postCouponNew = (obj, type) => {
    if (!type) {
        return
    }
    console.log(type, obj)
    let parm = {
        cardDays: 0,
        conditionNum: 0,
        expireDate: "",
        expireDays: 0,
        expireType: "",
        faceValue: 0,
        issueCount: 0,
        limitNum: 0,
        limitType: "",
        name: "",
        remark: "",
        status: "ENABLE", //新建默认状态
        subRemark: "",
        takeCondition: "NONE",
        takeCount: 0,
        takeDateEnd: "",
        takeDateStarted: "",
        type: type,
        useCount: 0,
        useDateStarted: ""
    }
    parm = Object.assign(parm, obj)

    console.log(parm)

    return axios.post(api.postCouponNew, parm)
        // return axios.post(api.postCouponNew, queryString.stringify(parm))
}

const postCheckUserValidate = (parm) => {
    console.log(parm)
    return axios.post(api.postCheckUserValidate, queryString.stringify(parm))
}

const postSendCoupon = (parm) => {
    console.log(parm)
    return axios.post(api.postSendCoupon, queryString.stringify(parm))
}

const postHandleCouponStatus = (parm) => { return axios.post(api.postHandleCouponStatus, queryString.stringify(parm)) }

const getCouponRecordList = (params) => {
    return axios.get(api.getCouponRecordList, { params: params })
}

const getCouponRecordExportExcel = (params) => {
    return axios.get(api.getCouponRecordExportExcel, { params: params })
}

const getCouponExchangeCode = (id) => {
    let params = { cardId: id }
    return axios.get(api.getCouponExchangeCode, { params: params })
}






export {
    api,
    postCouponList,
    getCouponLimitType,
    getCouponExpireType,
    postCouponNew,
    postHandleCouponStatus,
    getCouponDetail,
    postCheckUserValidate,
    postSendCoupon,
    getCouponRecordList,
    getCouponRecordExportExcel,
    getCouponExchangeCode,
}